package test1231.test2;

public class CC{
    String name;
    static EE[] emps = new EE[10];
    static int empCount = 0;
    public void add(String name, int age, int money){
        EE ee = new EE(name, age, money);
        add(ee);
    }
    public void add(EE ee){
        for(int i=0; i<emps.length; i++){
            if(emps[i]==null){
                emps[i] = ee;
                empCount++;
                break;
            }
        }
    }
    public void printAll(){
        for(int i=0; i<empCount; i++){
            System.out.println(emps[i]);
        }
    }
    public EE m1(){
        int maxAge = 0;
        int maxIndex = 0;
        for(int i=0; i<empCount; i++){
            if(emps[i].getAge() > maxAge){
                maxAge = emps[i].getAge();
                maxIndex = i;
            }
        }
        return emps[maxIndex];
    }
    public EE m2(){
        int minMoney = 0;
        int minIndex = 0;
        for(int i=0; i<empCount; i++){
            if(emps[i].getMoney() < minMoney){
                minMoney = emps[i].getMoney();
                minIndex = i;
            }
        }
        return emps[minIndex];
    }
    public EE m3(String name){
        for(int i = 0; i < empCount; i++){
            if(emps[i].getName() == name){
                return emps[i];
            }
        }
        return null;
    }
    public double m4() {
        int sum = 0;
        for(int i=0; i<empCount; i++){
            sum += emps[i].getMoney();
        }
        double avg = sum/empCount;
        return avg;
    }
    public void myfirst(int addmoney){
        for(int i=0; i<empCount; i++){
            emps[i].setMoney(emps[i].getMoney()+addmoney);
        }
        System.out.println("所有员工工资涨了"+addmoney+"元");
    }
    public void mysecond(){
        EE[] arr = mythird();
        for(int i=0; i<arr.length; i++){
            System.out.println(arr[i]);
        }

    }
    public EE[] mythird(){
        EE[] middle = new EE[empCount];
        int resultIndex = 0;
        for(int i=0; i<empCount; i++){
            if(emps[i].getMoney() > m4()){
                middle[resultIndex] = emps[i];
                resultIndex++;
            }
        }
        EE[] result = new EE[resultIndex];
        for(int i=0; i<resultIndex; i++){
            result[i] = middle[i];
        }
        return result;
    }


    public CC() {
    }

    public CC(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "CC{" +
                "name='" + name + '\'' +
                '}';
    }



}
